#include "head.h"
// 管理员 - 设定航班
void Management_Fly(F_list * Flight_list)
{
    const wchar_t *title_fly_l= L"设定航班";
    const wchar_t *option_fly_fly_l[] = {
    L"增加航班",
    L"减少航班",
    L"返回"};
    int flag = 0;
    flag = display_menu(title_fly_l, option_fly_fly_l, 3);
    switch (flag)
    {
    case 1:
        add_fly(Flight_list);
        break;
    case 2:
        delete_fly(Flight_list);
        break;
    case 3:
        return ;
    default:
        break;
    }
}
// 增加航班
void add_fly(F_list * Flight_list)
{
    F_data flight;
    printf("请按以下方式输入你要增加的航班\n");
    printf("班次 机型 起点站 终点站 起飞时间 到达时间 飞行时间 票价 载客量 剩余座位 是否飞\n");
    scanf("%d %s %s %s %d %d %d %d %s %d %d %d %c", &flight.id,flight.flighttype,flight.startcity,flight.arrivecity,
    &flight.starttime[0],&flight.starttime[1],&flight.arrivetime[0],&flight.arrivetime[1],flight.flytime,&flight.value,&flight.maxNUM,
    &flight.leftbuyersa,&flight.whetherfly);
    D_List_insert(Flight_list, flight, flight.id);
    printf("添加航班成功\n");
    sleep(2);
}

// 减少航班
void delete_fly(F_list * Flight_list)
{
    printf("以下是航班信息\n");
    D_List_print(Flight_list);
    int id;
    printf("请输入你要删除的航班的班次:");
    scanf("%d",&id);
    D_List_delete(Flight_list, id);
    D_List_file_print(Flight_list);
    printf("删除航班成功\n");
    sleep(2);
}

// 修改航班
void alter_Fly(F_list * Flight_list)
{
    printf("以下是航班信息\n");
    D_List_print(Flight_list);
    int id;
    printf("请输入你要修改的航班的id:");
    scanf("%d",&id);
    F_node * ptr = D_List_find_id(Flight_list, id);
    if(ptr== NULL)
    {
        printf("未找到航班\n");
        sleep(1);
        return ;
    }
    const wchar_t *title_fly = L"修改航班";
    const wchar_t *option_fly[] = {
    L"修改机型",
    L"修改起点站",
    L"修改终点站",
    L"修改飞行时间",
    L"修改票价",
    L"修改载客量",
    L"修改剩余座位",
    L"修改是否飞",
    L"返回"};
    int flag = 0;
    flag = display_menu(title_fly, option_fly, 9);
    switch (flag)
    {
        case 1:
            alter_flighttype(ptr);
            D_List_file_print(Flight_list);
            break;
        case 2:
            alter_startcity(ptr);
            D_List_file_print(Flight_list);
            break;
        case 3:
            alter_arrivecity(ptr);
            D_List_file_print(Flight_list);
            break;
        case 4:
            alter_flytime(ptr);
            D_List_file_print(Flight_list);
            break;
        case 5:
            alter_value(ptr);
            D_List_file_print(Flight_list);
            break;
        case 6:
            alter_maxNUM(ptr);
            D_List_file_print(Flight_list);
            break;
        case 7:
            alter_leftbuyersa(ptr);
            D_List_file_print(Flight_list);
            break;
        case 8:
            alter_whetherfly(ptr);
            D_List_file_print(Flight_list);
            break;
        case 9:
            return ;
        default:
            break;
    }
}
// 管理员 - 修改普通用户
void amend_users(FlightSystem * Flight_list)
{
    // 用户信息合表
    U_list *list = S_List_init();
    list = S_List_merge(list, Flight_list->ADMIN_USER);    // 管理员账户信息文件
    list = S_List_merge(list, Flight_list->REGULAR_USER);  // 普通用户信息文件
    list = S_List_merge(list, Flight_list->SILVER_USER);   // 银卡会员信息文件 (9折)
    list = S_List_merge(list, Flight_list->GOLD_USER);     // 金卡会员信息文件 (8折)
    list = S_List_merge(list, Flight_list->PLATINUM_USER); // 白金会员信息文件 (7折)
    printf("以下是所有用户信息\n");
    S_List_print(list);
    char name[128];
    printf("请输入你想要修改的用户\n");
    scanf("%s", name);
    U_node* ptr = S_List_find_name(list, name);
    if(ptr == NULL)
    {
        printf("无此用户\n");
        sleep(1);
        return;
    }
    int flag = 0;
    const wchar_t *title_DDDDD = L"修改普通用户";
    const wchar_t *option_DDDDD[] = {
    L"修改用户名",
    L"修改用户密码",
    L"修改用户等级",
    L"返回"};
    flag = display_menu(title_DDDDD, option_DDDDD, 4);
    switch (flag)
    {
        case 1:
            alter_name(ptr,Flight_list);
            break;
        case 2:
            alter_password(ptr,Flight_list);
            break;
        case 3:
            all_ch_grade (ptr,Flight_list);
            break;
        case 4:
            return ;
        default:
            break;
    }
    
}

// 管理员 - 所有用户等级修改
void all_ch_grade (U_node* ptr,FlightSystem * Flight_list)
{
    int flag = 0;
    const wchar_t *title_cicici = L"请选择你要将此用户调到什么等级";
    const wchar_t *option_cicici[] = {
    L"普通用户",
    L"白银会员",
    L"黄金会员",
    L"白金会员",
    L"管理员",
    L"返回"};
    flag = display_menu(title_cicici, option_cicici, 6);
    switch (flag)
    {
    case 1:
        Change_grade (Flight_list,ptr,1);
        break;
    case 2:
        Change_grade (Flight_list,ptr,2);
        break;
    case 3:
        Change_grade (Flight_list,ptr,3);
        break;
    case 4:
        Change_grade (Flight_list,ptr,4);
        break;
    case 5:
        Change_grade (Flight_list,ptr,5);
        break;
    default:
        break;
    }
}

// 管理员 - 更改超级用户
void super_users(U_list * Flight_list)
{
    int flag = 0;
    const wchar_t *title_cicici = L"更改超级用户";
    const wchar_t *option_cicici[] = {
    L"增加超级用户",
    L"减少超级用户",
    L"返回"};
    flag = display_menu(title_cicici, option_cicici, 3);
    switch (flag)
    {
        case 1:
            add_super_user(Flight_list);
            break;
        case 2:
            delete_super_user(Flight_list);
            break;
        default:
            break;
    }
}